package com.bjpowernode.money;
/*
    用于用户注册页面，返回给前端的提示信息
 */
import java.util.HashMap;
import java.util.Map;

//{"code":1,"message":"","success":true}
public class Result {


    public static Map<String,Object> success(){
        Map<String,Object> map=new HashMap<>();
        map.put("code",1);
        map.put("message","");
        map.put("success",true);
        return map;
    }

    public static Map<String,Object> success(String msg){
        Map<String,Object> map=new HashMap<>();
        map.put("code",1);
        map.put("message",msg);
        map.put("success",true);
        return map;
    }

    public static Map<String,Object> error(){
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("message","");
        map.put("success",false);
        return map;
    }

    public static Map<String,Object> error(String msg){
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("message",msg);
        map.put("success",false);
        return map;
    }
    public static Map<String,Object> error(Integer code,String msg){
        Map<String,Object> map=new HashMap<>();
        map.put("code",code);
        map.put("message",msg);
        map.put("success",false);
        return map;
    }

    //生成一个多少位的随机数
    public static String generateCode(int len){
        StringBuilder stringBuilder=new StringBuilder();
        for(int i=0;i<len;i++){
            /**
             * Math.random() 随机生成一个0-9之间的数
             * Math.round() 对一个数取整
             * stringBuilder 把这几个数给组装起来
             */
            stringBuilder.append(Math.round( Math.random()*9));
        }
        return stringBuilder.toString();
    }

}
